home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12175 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  64 lines

  1. Newsgroups: comp.lang.c
  2. Path: landen.math.uwaterloo.ca!srlalond
  3. From: srlalond@landen.math.uwaterloo.ca (Stephane Lalonde)
  4. Subject: Re: Settle a bet please
  5. Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
  6. Message-ID: <Dp1JBF.1uL@undergrad.math.uwaterloo.ca>
  7. Date: Fri, 29 Mar 1996 17:59:39 GMT
  8. References:  <4jfopb$o9n@news1.sympatico.ca>
  9. Nntp-Posting-Host: landen.math.uwaterloo.ca
  10. Organization: University of Waterloo
  11.  
  12. Hi Gisele,
  13.  
  14.  
  15. Here is some information that will help settle the bet.
  16.  
  17. 1.  Strings are supported in C by a combination of language
  18.     and library facilities
  19.  
  20. 2.  The language support ensure that all string constants end
  21.     with '\0';
  22.     i) character arrays MUST BE dimensioned 1 LARGER than
  23.         max required.
  24.  
  25. 3.  '\0' is used by the string routines to locate then end of
  26.     string, which has two draw-backs:
  27.     i)  a string cannot contain '\0'
  28.     ii) finding the end of the string = linear search
  29.  
  30. 4.  Finally, all storage management of C strings is the user's
  31.     responsibility.
  32.  
  33. So, if you wan't to be able to use functions such as:
  34.     printf("%s", Name);
  35.     strlen(Name);
  36. then you must declare name to be :
  37.     char Name[8];
  38.  
  39. Hope this helps,
  40.  
  41.  
  42. Stephane
  43.  
  44. In article <4jfopb$o9n@news1.sympatico.ca>, Gisele Swinson <gisele.swinson@sympatico.ca> writes:
  45. > In C language, how do they calculate the length of an array.
  46. > example
  47. > To declare a string "My Name"
  48. > is it char name[7] = "My Name"
  49. > or
  50. > is it chat Name[8] = "My Name"
  51. > There is a battle in my class whether to include the NULL in the
  52. > array size. 
  53. > I would appreciate any input you might have.
  54. > Thanks
  55. > Gisele
  56.